package com.foreknow.view;

import com.foreknow.dao.impl.BusinessDaoImpl;
import com.foreknow.model.Business;
import com.foreknow.service.BusinessService;
import com.foreknow.service.impl.BusinessServiceImpl;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.List;

public class BusinessTableModel extends AbstractTableModel {

    String[] columnNames = new String[]{"businessId", "businessName", "password", "businessAddress", "businessExplain", "starPrice", "deliveryPrice"};
    private List<Business> businesses = new ArrayList<>();

    public void setData(List<Business> list){
        this.businesses = list;
        this.fireTableDataChanged();
    }

    @Override
    public int getRowCount() {
        return businesses.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Business h = businesses.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return h.getBusinessId();
            case 1:
                return h.getBusinessName();
            case 2:
                return h.getBusinessPassword();
            case 3:
                return h.getBusinessAddress();
            case 4:
                return h.getBusinessExplain();
            case 5:
                return h.getStarPrice();
            case 6:
                return h.getDeliveryPrice();
        }
        return null;

    }
}
